const { connection } = require('../config/mysql');

// 批量添加账单表数据
const setBill = async (values) => {
    try {
        let sqlQuery = '';
        // console.log(values[128]);
        for (let i = 0; i < values.length; i++) {
            const row = values[i];
            sqlQuery += `( '${row[0]}', '${row[1]}',${row[2]},'${row[3]}','', '${row[4]}',${row[5]},${row[6]},'${row[7]}','${row[8]}','${row[9]}','${row[10]}',2 ), `;
        }
        
        sqlQuery = sqlQuery.slice(0, -2);
        console.log(sqlQuery);
        // const insertStatement = `INSERT INTO bill (id, payTime, transactionType,trader, tradingAccount, notes,type, money, paymentMethod,transactionOrderNumber, merchantOrderNumber, userId, payType) VALUES ${sqlQuery}`;
        // connection.query(insertStatement, (err, result) => {
        //     if (err) throw err;
        //     console.log(`Inserted ${result.affectedRows} rows.`);
            
        //     // 关闭数据库连接
        //     // connection.end();
        //   });
        return { 
            status: 1,
            msg: '执行成功'
        }
    } catch (error) {
        console.error(error)
        return {
            status: -1,
            msg: error
        }
    }
}

const getUser = async () => {
    try {
        return await executeQuery('mine', `select * from user`, (rows) => {
            console.log('callback', rows)
            return rows
        })
    } catch (error) {
        console.error(error)
        throw error + ' 查询失败'
    }
}

module.exports = {
    setBill,
    getUser
}